﻿using System;
using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Resources;
using System.Windows.Shapes;

namespace JsonTest1.Utils
{
    public class FileUtil
    {
        public static void CopyToIsolatedStorage(string[] urls)
        { 
        
            using(IsolatedStorageFile storage=IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (urls != null)
                {
                    foreach (var filePath in urls)
                    {
                        if (!storage.FileExists(filePath))
                        {
                            StreamResourceInfo resource = Application.GetResourceStream(new Uri(filePath,UriKind.Relative));
                            using (IsolatedStorageFileStream file = storage.CreateFile("test_cbr.mp3"))
                            {

                                int chunkSize = 4096;

                                byte[] bytes = new byte[chunkSize];

                                int byteCount;



                                while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                                {

                                    file.Write(bytes, 0, byteCount);

                                }

                            }


                        }
                    }
                }
            }
        }
    }
}
